package org.agile2soft.nexoma.core.entities;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
@Table(name="SERVICE", uniqueConstraints = { @UniqueConstraint(columnNames = {"SER_ID","SEG_ID"})} )
@SuppressWarnings({"serial"})
public class Service implements java.io.Serializable {

    private Integer id;
    private String  name;
    private String  url;
    private String  comments;
    private boolean active;
    private boolean editable;
    private String  mode;
    private ServicesGroup group;
    private Set<ServiceOption> options = new HashSet<ServiceOption>(0);
    private Set<Profile> profiles = new HashSet<Profile>(0);

    public String toString() {
        return String.format("[Service %s,%s,%s,%s,%s,%s,%s,%s]",id,name,url,comments,active,editable,mode);
    }
    public Service(){
    }

    public Service(String name, boolean active, boolean editable, ServicesGroup group) {
        this.name = name;
        this.active = active;
        this.editable = editable;
        this.group=group;
    }

    public Service(String name, String url, String comments,
            boolean active, boolean editable, String mode, ServicesGroup group) {
        this.name=name;
        this.url = url;
        this.comments = comments;
        this.active=active;
        this.editable=editable;
        this.mode=mode;
        this.group = group;
    }

    public Service(String name, boolean action, String url,
                  String comments, boolean active, boolean editable,
                  String mode, ServicesGroup group,  Set<ServiceOption>options, Set<Profile> profiles) {
        this.name=name;
        this.url = url;
        this.comments = comments;
        this.active=active;
        this.editable=editable;
        this.mode=mode;
        this.group = group;
        this.options=options;
        this.profiles=profiles;
    }

    @Id
    @GeneratedValue(strategy=IDENTITY)
    @Column(name="SER_ID", unique=true,nullable=false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name="SER_NAME",unique=true,nullable=false,length=30)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="SER_URL",nullable=true,length=200,unique=true)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(name="SER_COMMENTS",nullable=true,length=100)
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @Column(name="SER_ACTIVE",nullable=false)
    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @Column(name="SER_EDITABLE",nullable=false)
    public boolean isEditable() {
        return editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    @Column(name="SER_MODE",nullable=false)
    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="SEG_ID",nullable=false,updatable=false)
    public ServicesGroup getGroup (){
        return this.group;
    }

    public void setGroup ( ServicesGroup group ) {
        this.group = group;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "service")
    public Set<ServiceOption> getOptions() {
        return this.options;
    }

    public void setOptions(Set<ServiceOption>options) {
        this.options=options;
    }

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "services")
    public Set<Profile> getProfiles() {
        return this.profiles;
    }

    public void setProfiles(Set<Profile>profiles) {
        this.profiles=profiles;
    }
}
